﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

// Token: 0x020003C0 RID: 960
public class ThumbnailSelectUI : MonoBehaviour
{
	// Token: 0x17000257 RID: 599
	// (get) Token: 0x060017EE RID: 6126 RVA: 0x0009CF9C File Offset: 0x0009B19C
	// (set) Token: 0x060017EF RID: 6127 RVA: 0x0009CFA4 File Offset: 0x0009B1A4
	public int SelectNo { get; private set; }

	// Token: 0x060017F0 RID: 6128 RVA: 0x0009CFB0 File Offset: 0x0009B1B0
	private void Awake()
	{
		this.SelectNo = -1;
		this.bigThumbsRoot.SetActive(false);
	}

	// Token: 0x060017F1 RID: 6129 RVA: 0x0009CFC8 File Offset: 0x0009B1C8
	private void SetupCells()
	{
		this.DeleteCells();
		if (this.datas == null || this.datas.Count == 0)
		{
			return;
		}
		this.cells = new ThumbnailSelectCell[this.datas.Count];
		for (int i = 0; i < this.datas.Count; i++)
		{
			bool isNew = this.datas[i].isNew;
			ThumbnailSelectCell thumbnailSelectCell = UnityEngine.Object.Instantiate<ThumbnailSelectCell>(this.cellOriginal);
			thumbnailSelectCell.gameObject.SetActive(true);
			thumbnailSelectCell.Setup(this, i, this.datas[i].name, this.datas[i].thumbnail_S, isNew);
			thumbnailSelectCell.transform.SetParent(this.contentRoot, false);
			this.cells[i] = thumbnailSelectCell;
		}
		Vector2 anchoredPosition = this.contentRoot.anchoredPosition;
		anchoredPosition.y = 0f;
		this.contentRoot.anchoredPosition = anchoredPosition;
		this.scrollRect.Rebuild(CanvasUpdate.PostLayout);
	}

	// Token: 0x060017F2 RID: 6130 RVA: 0x0009D0CC File Offset: 0x0009B2CC
	private void DeleteCells()
	{
		if (this.cells != null)
		{
			for (int i = 0; i < this.cells.Length; i++)
			{
				UnityEngine.Object.Destroy(this.cells[i].gameObject);
			}
		}
		this.cells = null;
	}

	// Token: 0x060017F3 RID: 6131 RVA: 0x0009D118 File Offset: 0x0009B318
	public void SetDatas(List<CustomSelectSet> setDatas)
	{
		this.datas = setDatas;
		this.SetupCells();
		this.SelectNo = -1;
		this.bigThumbsRoot.SetActive(false);
	}

	// Token: 0x060017F4 RID: 6132 RVA: 0x0009D13C File Offset: 0x0009B33C
	private void Update()
	{
	}

	// Token: 0x060017F5 RID: 6133 RVA: 0x0009D140 File Offset: 0x0009B340
	public void OnEnterCell(int no)
	{
		if (this.datas == null)
		{
			return;
		}
		if (this.overlapID != no)
		{
			this.overlapID = no;
			this.bigThumbsImage.sprite = this.datas[no].thumbnail_L;
			this.bigThumbsText.text = this.datas[no].name;
			bool active = this.bigThumbsImage.sprite != null;
			this.bigThumbsRoot.SetActive(active);
		}
	}

	// Token: 0x060017F6 RID: 6134 RVA: 0x0009D1C4 File Offset: 0x0009B3C4
	public void OnExitCell(int no)
	{
		if (this.overlapID == no)
		{
			this.overlapID = -1;
			this.bigThumbsRoot.SetActive(false);
		}
	}

	// Token: 0x060017F7 RID: 6135 RVA: 0x0009D1E8 File Offset: 0x0009B3E8
	public void OnSelect(int no)
	{
		this.SelectNo = no;
		if (!this.invoke)
		{
			return;
		}
		if (this.onSelectAction != null)
		{
			this.onSelectAction.Invoke(this.GetSelectedData());
		}
		SystemSE.Play(SystemSE.SE.CHOICE);
		if (no >= 0)
		{
			this.datas[no].isNew = false;
		}
	}

	// Token: 0x060017F8 RID: 6136 RVA: 0x0009D244 File Offset: 0x0009B444
	public CustomSelectSet GetData(int listNo)
	{
		if (this.datas == null)
		{
			return null;
		}
		if (listNo >= 0 && listNo < this.datas.Count)
		{
			return this.datas[listNo];
		}
		return null;
	}

	// Token: 0x060017F9 RID: 6137 RVA: 0x0009D27C File Offset: 0x0009B47C
	public CustomSelectSet GetSelectedData()
	{
		if (this.datas == null)
		{
			return null;
		}
		if (this.SelectNo >= 0 && this.SelectNo < this.datas.Count)
		{
			return this.datas[this.SelectNo];
		}
		return null;
	}

	// Token: 0x060017FA RID: 6138 RVA: 0x0009D2CC File Offset: 0x0009B4CC
	public void SetSelectedNo(int no)
	{
		this.invoke = false;
		this.SelectNo = no;
		for (int i = 0; i < this.cells.Length; i++)
		{
			this.cells[i].SetToggle(no == i);
		}
		this.invoke = true;
	}

	// Token: 0x060017FB RID: 6139 RVA: 0x0009D318 File Offset: 0x0009B518
	public void SetSelectedFromDataID(int id)
	{
		this.invoke = false;
		this.SelectNo = -1;
		if (this.datas != null && this.cells != null)
		{
			for (int i = 0; i < this.datas.Count; i++)
			{
				if (this.datas[i].id == id)
				{
					this.SelectNo = i;
					break;
				}
			}
			for (int j = 0; j < this.cells.Length; j++)
			{
				this.cells[j].SetToggle(this.SelectNo == j);
			}
		}
		this.invoke = true;
	}

	// Token: 0x060017FC RID: 6140 RVA: 0x0009D3C0 File Offset: 0x0009B5C0
	public void AddOnSelectAction(UnityAction<CustomSelectSet> act)
	{
		this.onSelectAction.AddListener(act);
	}

	// Token: 0x060017FD RID: 6141 RVA: 0x0009D3D0 File Offset: 0x0009B5D0
	public void RemoveAllListenersOnSelectAction()
	{
		this.onSelectAction.RemoveAllListeners();
	}

	// Token: 0x060017FE RID: 6142 RVA: 0x0009D3E0 File Offset: 0x0009B5E0
	public List<CustomSelectSet> GetDatas()
	{
		return this.datas;
	}

	// Token: 0x060017FF RID: 6143 RVA: 0x0009D3E8 File Offset: 0x0009B5E8
	public void UpdateEnables()
	{
		if (this.cells == null)
		{
			return;
		}
		for (int i = 0; i < this.cells.Length; i++)
		{
			this.cells[i].gameObject.SetActive(!this.datas[i].hide);
			this.cells[i].SetInteractable(this.datas[i].enable);
		}
	}

	// Token: 0x04001B5B RID: 7003
	[SerializeField]
	private RectTransform contentRoot;

	// Token: 0x04001B5C RID: 7004
	[SerializeField]
	private ThumbnailSelectCell cellOriginal;

	// Token: 0x04001B5D RID: 7005
	[SerializeField]
	private GameObject bigThumbsRoot;

	// Token: 0x04001B5E RID: 7006
	[SerializeField]
	private Image bigThumbsImage;

	// Token: 0x04001B5F RID: 7007
	[SerializeField]
	private Text bigThumbsText;

	// Token: 0x04001B60 RID: 7008
	[SerializeField]
	private List<CustomSelectSet> datas = new List<CustomSelectSet>();

	// Token: 0x04001B61 RID: 7009
	private ThumbnailSelectCell[] cells;

	// Token: 0x04001B62 RID: 7010
	private int overlapID = -1;

	// Token: 0x04001B64 RID: 7012
	[SerializeField]
	private ThumbnailSelectUI.CustomSelEvent onSelectAction;

	// Token: 0x04001B65 RID: 7013
	[SerializeField]
	private ScrollRect scrollRect;

	// Token: 0x04001B66 RID: 7014
	private bool invoke = true;

	// Token: 0x020003C1 RID: 961
	[Serializable]
	private class CustomSelEvent : UnityEvent<CustomSelectSet>
	{
	}
}
